//------------------------------------------------------------------------------
// Copyright (c) 2008 www.dnaide.com
// Licensed under the MIT (MIT-LICENSE.txt)
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace DNAide.Configuration
{

	/// <summary>
	/// UrlRewiter config
	/// </summary>
	public class UrlRewriterConfig : ConfigurationElement
	{

		/// <summary>UrlRewriterConfig</summary>
		public UrlRewriterConfig()
		{
		}

		/// <summary>
		/// Regex complition mode for pattern matching rules. Default is "Compiled"
		/// </summary>
		[ConfigurationProperty("regexCompilationMode", DefaultValue = "Compiled", IsRequired = false)]
		public RegexCompilationType RegexCompilationMode
		{
			get
			{
				return (RegexCompilationType)this["regexCompilationMode"];
			}
			set
			{
				this["regexCompilationMode"] = value;
			}
		}

		/// <summary>
		/// How the rewriter prioritises it's search i.e. rules or sitemap search. Default is "Rules" first.
		/// If your site is heavily based on the sitemap, it is recommended to set this value to SiteMap
		/// </summary>
		[ConfigurationProperty("searchPriority", DefaultValue = "Rules", IsRequired = false)]
		public UrlRewriterSearchPriorityType SearchPriority
		{
			get
			{
				return (UrlRewriterSearchPriorityType)this["searchPriority"];
			}
			set
			{
				this["searchPriority"] = value;
			}
		}

		/// <summary>
		/// Event in the request lifecycle when the rewriter works. Default "BeginRequest".
		/// </summary>
		[ConfigurationProperty("firesOnEvent", DefaultValue = "BeginRequest", IsRequired = false)]
		public HttpModuleFiringEvent FiresOnEvent
		{
			get
			{
				return (HttpModuleFiringEvent)this["firesOnEvent"];
			}
			set
			{
				this["firesOnEvent"] = value;
			}
		}


		/// <summary>
		/// If true, the rewriter will only work with virtual urls i.e. that the file does not physically exist on the server.
		/// Default "true"
		/// </summary>
		[ConfigurationProperty("virtualUrlsOnly", DefaultValue = true, IsRequired = false)]
		public Boolean VirtualUrlsOnly
		{
			get
			{
				return (bool)this["virtualUrlsOnly"];
			}
			set
			{
				this["virtualUrlsOnly"] = value;
			}
		}

		/// <summary>
		/// File types that the rewriter will deal with. Default ".htm,.aspx".
		/// You can map all file types by setting this value to be ".*" if required.
		/// </summary>
		[ConfigurationProperty("applicableFileExtensions", DefaultValue = ".htm,.aspx", IsRequired = false)]
		public String ApplicableFileExtensions
		{
			get
			{
				return (string)this["applicableFileExtensions"];
			}
			set
			{
				this["applicableFileExtensions"] = value;
			}
		}


		/// <summary>
		/// The is the default page that is automatically appended to the request if the user has not requested a page i.e. a folder only.
		/// Similar to default page of IIS.
		/// <example>
		/// User requested: http://www.mywebsite.com/news
		/// The rewriter, before performing any rule matches or before it looks in the sitemap, will append a default page here e.g.
		/// Url modified: http://www.mywebsite.com/news/index.htm
		/// </example>
		/// </summary>
		[ConfigurationProperty("defaultPage", IsRequired = true)]
		public String DefaultPage
		{
			get
			{
				return (string)this["defaultPage"];
			}
			set
			{
				this["defaultPage"] = value;
			}
		}


		/// <summary>
		/// You can specify the default url that all SiteMap nodes rewrite to. For example, you may wish to rewrite all nodes to ~/_Templates/DefaultTemplate.aspx.
		/// You can then override this value at the SiteMap node level. 
		/// </summary>
		[ConfigurationProperty("defaultSiteMapNodeRewriteUrl", IsRequired = false)]
		public String DefaultSiteMapNodeRewriteUrl
		{
			get
			{
				return (string)this["defaultSiteMapNodeRewriteUrl"];
			}
			set
			{
				this["defaultSiteMapNodeRewriteUrl"] = value;
			}
		}


		/// <summary>
		/// Collection of rewriter rules
		/// </summary>
		[ConfigurationProperty("rules", IsRequired = false, IsDefaultCollection=true)]
		public UrlRewriterRuleConfigCollection Rules
		{
			get
			{
				return (UrlRewriterRuleConfigCollection)this["rules"];
			}
		}

	}

}
